
time=$(date "+%Y-%m-%d %H:%M:%S")
echo "##################${time} Begin Sync Code#######################"  >> syncLog.txt 2>&1
##common
# cd common
## 显示< name>的值时作为一个象征性的参考，试图缩短价值，例如从refs/heads/master到master
# common_branch_name=`gHEAD`
# echo "###common's current branch is ${common_branch_name}###" >> ./syncLog.txt 2>&1
# git checkout master >> ./syncLog.txt 2>&1
# git fetch upstream >> ./syncLog.txt 2>&1
# git rebase upstream/master >> ./syncLog.txt 2>&1
# git push >> ./syncLog.txt 2>&1
# git checkout $common_branch_name >> ./syncLog.txt 2>&1
# git rebase master >> ./syncLog.txt 2>&1
# git push >> ./syncLog.txt 2>&1
 
##api
# cd ../api
# api_branch_name=`git symbolic-ref --short -q HEAD`
# echo "###api's current branch is ${api_branch_name}###" >> ../syncLog.txt 2>&1
# git checkout master >> ../syncLog.txt 2>&1
# git fetch upstream >> ../syncLog.txt 2>&1
# git rebase upstream/master >> ../syncLog.txt 2>&1
# git push >> ../syncLog.txt 2>&1
# git checkout $api_branch_name >> ../syncLog.txt 2>&1
# git rebase master >> ../syncLog.txt 2>&1
# git push >> ../syncLog.txt 2>&1

# ---


 
# while true
# do
#     read -r -p "确定要 强制 拉取远程吗? Are You Sure? [Y/n] " input
 
#     case $input in
#         [yY][eE][sS]|[yY])
#             echo "Yes"echo "###Force push the local master branch to the remote###" | tee -a ./syncLog.txt
#             # 切换到master
#             git checkout master | tee -a ./syncLog.txt
#             # 强制拉取远程到本地
#             git fetch --all  | tee -a ./syncLog.txt
#             git reset --hard origin/master  | tee -a ./syncLog.txt #(这里dev要修改为对应的分支名) 
#             git pull origin master | tee -a ./syncLog.txt
#             exit 1
#             ;;
 
#         [nN][oO]|[nN])
#             echo "No"
#             exit 1               
#             ;;
 
#         *)
#             echo "Invalid input..."
#             ;;
#     esac
# done

# ---
 
while true
do
    read -r -p "确定要 推送 到远程吗? Are You Sure? [Y/n] " input
 
    case $input in
        [yY][eE][sS]|[yY])
            echo "Yes"
            echo "###Push the local master branch to the remote###" | tee -a ./syncLog.txt 
            # 切换到master
            git checkout master | tee -a ./syncLog.txt 
            # 添加本地文件到缓存
            git add . | tee -a ./syncLog.txt 
            # 添加commit日期
            git commit -m $(date +%Y-%m-%d-%H:%M:%S) | tee -a ./syncLog.txt 
            # 推送到 master
            git push origin master  | tee -a ./syncLog.txt 
            exit 1
            ;;
 
        [nN][oO]|[nN])
            echo "No"
            exit 1               
            ;;
 
        *)
            echo "Invalid input..."
            ;;
    esac
done